package com.bjqh.edu.UI.Activity.StudentPersonal;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Bean.Login;
import com.bjqh.edu.Bean.User;
import com.bjqh.edu.R;
import com.bjqh.edu.UI.Activity.Login.LoginActivity;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.generic.RoundingParams;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpParams;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

public class OpinionActivity extends AppCompatActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_qx)
    TextView tvQx;
    @BindView(R.id.rl_top_tilte)
    RelativeLayout rlTopTilte;
    @BindView(R.id.et_op)
    EditText etOp;
    @BindView(R.id.tv_ok)
    Button tvOk;
    private ProgressDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_opinion);
        ButterKnife.bind(this);
        tvTitle.setText("意见反馈");
        dialog = new ProgressDialog(this);
        dialog.setMessage("火速加载中…");
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (TextUtils.isEmpty(etOp.getText())) {
                    Toast.makeText(OpinionActivity.this, "小主，给点意见呗~~~~", Toast.LENGTH_SHORT).show();
                    etOp.requestFocus();
                    return;

                }
                dialog.show();
                HttpParams params=AppConstants.initPram();
                params.put("content",etOp.getText().toString());
                OkGo.post(AppConstants.BASE_URL + "/feed/addOrUpdate.shtml")
                        .tag(this)
                        .cacheKey("cacheKey")
                        .cacheMode(CacheMode.DEFAULT)
                        .params(params)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(String s, okhttp3.Call call, okhttp3.Response response) {
                                AppConstants.removeDialog(dialog);
                                Log.e("意见反馈",s);
                                Gson gson = new Gson();
                                Login login = gson.fromJson(s, Login.class);
                                if (login.getMsg().equals("timeout"))
                                {
                                    startActivity(new Intent(OpinionActivity.this, LoginActivity.class));
                                }
                                else {
                                    Toast.makeText(OpinionActivity.this, "感谢小主，您宝贵的意见会使我更加完美~~" , Toast.LENGTH_SHORT).show();
                                    finish();
                                }


                            }

                            @Override
                            public void onError(Call call, Response response, Exception e) {
                                Toast.makeText(OpinionActivity.this, "报告小主，服务器被外星人偷走啦~~" , Toast.LENGTH_SHORT).show();
                            }
                        });
            }
        });

    }
}
